package com.mrd.gtimp.business.service;

import com.mrd.base.BaseBiz;
import com.mrd.gtimp.base.entity.Company;
import com.mrd.gtimp.business.entity.FundReport;
import com.mrd.spring.repository.BaseRepository;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

/**
 * <p> application name: gtimp <p> copyright: Copyright@2012 明睿达科技有限公司
 */

/**
 * @author luob
 */
@Service
public class FundReportBiz extends BaseBiz<FundReport> {

    @Resource
    // 该处指定注入BaseRepository的dao对象
    @Qualifier("fundReportDao")
    public void setBaseRepository(BaseRepository<FundReport, String> baseRepository) {
        super.baseRepository = baseRepository;
    }

    Logger log = Logger.getLogger(FundReportBiz.class);


    public FundReport findLatestReport(Company owner) {
        List<FundReport> results = findEntityByHql("select t from com.mrd.gtimp.business.pojo.FundReport t where owner.id='"
                + owner.getId() + "' order by regDate desc", 1, 1, null);
        return results == null || results.size() == 0 ? null : results.get(0);
    }


    public void delReport(Company owner) {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("OWNERID", owner.getId());
        try {
            /**
             * 删除最新的记录
             */
            getBaseRepository().excuteSql("DELETE FROM T_BIZ_FUND_REPORT WHERE ID IN (SELECT ID FROM (SELECT T.*,ROWNUM FROM T_BIZ_FUND_REPORT T WHERE T.COM_ID=:OWNERID ORDER BY REG_DATE DESC) WHERE ROWNUM=1)", parameters);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
